<template>
  <div class="machine-list">
    <van-nav-bar
        left-arrow
        @click-left="onClickLeft"
        title="设备管理"
    />
    <div class="top-btn">
      <van-button type="primary" color="#1e98dc" block round @click="goAdd">新增设备</van-button>
    </div>
    <div class="table-container">
      <div v-if="tableData.length>0">
        <div class="list-item" v-for="(item,i) in tableData" :key="this">
          <van-swipe-cell>
            <div class="list-item-main-text" @click="goDetail(item)">
              <van-row>
                <van-col span="20">
                  <div>
                    <div class="item-text">
                      <div>
                        <span>{{ item.id }}</span> <span style="margin-left: 10px;">{{ item.name }}</span>
                      </div>
                    </div>
                    <div class="item-text">
                      <div>
                        {{ item.address }}
                      </div>
                    </div>
                  </div>
                </van-col>
                <van-col span="4">
                  <div class="item-text item-text-go-detail">
                    <div class="go-detail">
                      <van-icon name="arrow" color="blue" size="20px"/>
                    </div>
                  </div>
                </van-col>
              </van-row>
            </div>
            <template #right>
              <van-button square text="删除" type="danger" class="delete-button"/>
            </template>
          </van-swipe-cell>
        </div>
      </div>
      <div v-if="total<=0">
        <van-empty description="暂无数据"/>
      </div>
    </div>
  </div>
</template>

<script>
import {machineList} from "@/api/operator";
import {getLocalOpenId} from "@/utils/wxUtil";

export default {
  data() {
    return {
      loading: false,
      tableData: [],
      total: 10,
      queryParams: {
        pageNo: 1,
        pageSize: 10
      }
    };
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1)
    },
    getList() {
      this.loading = true
      let params = {
        openId: getLocalOpenId()
      }
      machineList(params).then(res => {
        this.total = res.total
        this.tableData = this.tableData.concat(res.rows ? res.rows : [])
      })
      this.loading = false
    },
    goAdd() {
      this.$router.push("/operator/machine/add")
    },
    goDetail(item) {
      this.$router.push({
        path: "/operator/machine/detail",
        query: {
          id: item.id
        }
      })
    },
  },
  mounted() {
    this.getList()
  }
};
</script>

<style lang="less" scoped>
.machine-list {
  min-height: 80vh;
  background: #f7f8fa;
  padding-bottom: 100px;
  padding-top: 50px;

  .van-nav-bar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 99;
    width: 100%;
    //background: #1e98dc;

    .van-nav-bar__title,
    .van-nav-bar__text,
    .van-icon-arrow-left {
      color: #fff;
    }
  }

  .top-btn {
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 10;
    background: #fff;
    border-top: 1px solid #ddd;
    padding: 10px 0;

    .van-button {
      width: 90%;
      margin: 0 auto;
    }
  }

  .table-main {
    border-top: 1px #efefef solid;
  }

  .list-item {
    margin-top: 10px;

    .titlename {
      font-size: 18px;
    }

    .van-collapse-item__content {
      background: #efefef;
    }

    .van-collapse-item__title--expanded {
      box-shadow: 0 5px 5px rgba(126, 126, 126, 0.1);
    }

    .title-cell {
      border-bottom: 1px solid #ebedf0;
      white-space: nowrap;

      &::after {
        border: none;
      }
    }

    .van-collapse-item--border::after {
      border: none;
    }

    .list-item-main-text {
      background: #fff;
      padding: 10px 30px;
      font-size: 14px;

      .item-text {
        padding: 3px 0;
        display: flex;
      }

      .item-text-go-detail {
        .go-detail {
          margin: auto;
          padding: 12px;
        }
      }
    }
  }

  .list-item-btnbox {
    border-top: solid 1px #ebedf0;
    border-bottom: solid 1px #ebedf0;
    background: #fff;
    padding: 0 5px;
    height: 32px;

    .list-item-btnmain1 {
      float: left;

      .van-button {
        padding: 5px 5px;
        margin-left: 5px;
        min-width: 60px;
        font-size: 13px;
      }
    }

    .list-item-btnmain2 {
      float: right;

      .van-button {
        padding: 5px 5px;
        margin-left: 5px;
        min-width: 60px;
        font-size: 13px;
      }
    }
  }

  .clear {
    clear: both;
  }

}

.van-button--small {
  height: 20px;
}

.delete-button {
  height: 100%;
}
</style>
